package com.lmx.repoDomain.repository;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.persistence.service.AppraiseService;
import com.lmx.repoDomain.tmodel.Appraise;

import io.katharsis.repository.annotations.JsonApiResourceRepository;
import io.katharsis.repository.annotations.JsonApiSave;

/**
 * 评价
 *
 * @author ytche
 * @date 2017年7月21日
 *
 */
@JsonApiResourceRepository(Appraise.class)
@Component
public class AppraiseRepository extends BaseRepository<Appraise> {
	@Autowired
	private AppraiseService service;

	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(Appraise.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	@JsonApiSave
	public Appraise save(final Appraise entity) {
		if (entity.getId() != null && service.checkPublish(entity)) {
			this.service.publish(entity);
		}
		return super.save(entity);
	}
}
